package com.dlry.serviceImpl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dlry.db.MeetingRoomRepository;
import com.dlry.entity.DlMeetingRoom;
import com.dlry.entity.DlMeetingRoomBooking;

@Service
@Transactional
public class MeetingRoomServiceImpl implements MeetingRoomService {

	private MeetingRoomRepository meetingRoomRepository;

	@Autowired
	public MeetingRoomServiceImpl(MeetingRoomRepository meetingRoomRepository) {
		this.meetingRoomRepository = meetingRoomRepository;
	}

	public List<DlMeetingRoom> finaAll() {
		return meetingRoomRepository.findAll();
	}

	public void save(DlMeetingRoom room) {
		meetingRoomRepository.save(room);
	}

	public void update(DlMeetingRoom room) {
		meetingRoomRepository.save(room);
	}

	public List<DlMeetingRoomBooking> getBookingsByIdFrom(Long rId, Timestamp timestamp) {
		List<DlMeetingRoomBooking> bookings = meetingRoomRepository.getBookingsByIdFrom(rId, timestamp);
		return bookings;
	}

	public List<DlMeetingRoomBooking> getBookingsByIdBetween(Long rId, Timestamp startDay, Timestamp entDay) {

		return meetingRoomRepository.getBookingsByIdBetween(rId, startDay, entDay);
	}

	public DlMeetingRoom findById(Long rId) {
		return meetingRoomRepository.findOne(rId);
	}

	public Page<DlMeetingRoom> findAll(Integer page, Integer row) {
		Pageable pageable = new PageRequest(page, row);
		Page<DlMeetingRoom> rooms = meetingRoomRepository.findAll(pageable);
		return rooms;
	}

	public void delete(Long id) {
		meetingRoomRepository.delete(id);
	}

}
